
package view.calendario;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import view.DateJDialog;
import view.iscrizioni.GiocatoreListModel;
import view.iscrizioni.InscrizioneTorneoSingolo;

import model.core.torneo.Gara;
import model.core.torneo.Torneo;
import model.core.utente.Giocatore;
import model.core.utente.GiocatoreInterface;
import model.persistence.DAOManager;
import model.persistence.mysql.DAOManager_MySQL;
import model.utility.Utility;


/**
 * 
 * @author Giuseppe Fusco (fusgius19@gmail.com)
 *
 */
public class DefinizioneCalendario extends javax.swing.JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6759359790493771425L;
	private Torneo torneo;
	private DAOManager d;
	private List<? extends GiocatoreInterface> giocatori;
	private ArrayList<Integer> vt;
	private Gara gara;

	private SwingWorker<List<? extends GiocatoreInterface>, Giocatore> sw = new SwingWorker<List<? extends GiocatoreInterface>, Giocatore>() {
		@Override
		protected List<Giocatore> doInBackground()
				throws Exception {
			// TODO Auto-generated method stub
			giocatori = (List<? extends GiocatoreInterface>) (torneo.isSingolo()?d.getGiocatoreDao().load(""):d.getSquadraDao().load(""));
			nomeTorneo.setText(torneo.getNome());
			tipologiaTorneo.setText(torneo.getTipologia());
			numeroEdizioneTorneo.setText(String.valueOf(torneo.getNumero_edizione()));
			annoSvolgimentoTorneo.setText(String.valueOf(torneo.getAnno_svolgimento()));
			nroCommissari.setText(String.valueOf(torneo.getCommissione().getCommissione().size()));
			totPartecipanti.setText(String.valueOf(torneo.getClassifica().getGiocatori().size()));
			tipoGiocatori.setText(torneo.isSingolo()?"GIOCATORI":"SQUADRE");
			loadList();
			addListener();
			return (List<Giocatore>) giocatori;
		}

	};

	public static void main(String[] arg){
		try {
			for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
				if ("Nimbus".equals(info.getName())) {
					javax.swing.UIManager.setLookAndFeel(info.getClassName());
					break;
				}
			}
		} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
			java.util.logging.Logger.getLogger(InscrizioneTorneoSingolo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
		}
		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				JFrame f = new JFrame();
				f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
				try {
					f.add(new DefinizioneCalendario(
							DAOManager_MySQL.getInstance()
							.getTorneoDao().load("pippo").get(0),DAOManager_MySQL.getInstance()));
				} catch (ClassNotFoundException | SQLException | IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				f.pack();
				f.setVisible(true);
			}
		});

	}

	/**
	 * Creates new form DefinizioneCalendario
	 */
	public DefinizioneCalendario(Torneo torneo, DAOManager d) {
		initComponents();
		this.torneo = torneo;
		vt = new ArrayList<Integer>();
		this.d = d;
		sw.execute();
	}

	private void loadList(){
		listGiocatori.setCellRenderer(new SfidanteCellRenderer(vt));
		listGiocatori.setModel(new GiocatoreListModel(giocatori));
		listGare.setModel(new GaraListModel(torneo.getCalendario().getCalendario()));
		totGare.setText(String.valueOf(torneo.getCalendario().getCalendario().size()));
		listGare.addListSelectionListener(new ListSelectionListener() {

			@Override
			public void valueChanged(ListSelectionEvent arg0) {
				// TODO Auto-generated method stub
				if(!arg0.getValueIsAdjusting() && listGare.getSelectedIndex()>=0){
					vt.removeAll(vt);
					gara = torneo.getCalendario().getCalendario().get(listGare.getSelectedIndex()).getX();
					for(GiocatoreInterface g: giocatori){
						if(Utility.isThereGiocatore(gara.getGiocatori(), g))
							vt.add(new Integer(giocatori.indexOf(g)));
					}
					listGiocatori.setCellRenderer(new SfidanteCellRenderer(vt));
					nomeGara.setText(gara.getNome());
					nroGiorniDaDisputare.setText(String.valueOf(gara.getNro_giorni_da_disputare()));
					dataInizio.setText(Utility.SDF.format(gara.getData_inizio().getTime()));
					dataFine.setText(Utility.SDF.format(gara.getData_fine().getTime()));
					tipoGara.setSelectedIndex(gara.isSync()?1:0);
					totSfidanti.setText(String.valueOf(gara.getGiocatori().size()));
				}
			}
		});
	}

	private void addListener(){
		tipoGara.addItemListener(new ItemListener() {

			@Override
			public void itemStateChanged(ItemEvent arg0) {
				// TODO Auto-generated method stub
				if(tipoGara.getSelectedIndex()==0 && listGare.getSelectedIndex()>=0)
					gara.setSync(false);
				else if(tipoGara.getSelectedIndex()==1 && listGare.getSelectedIndex()>=0)
					gara.setSync(true);

			}
		});

		addnroGiorniDaDisputare.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if(listGare.getSelectedIndex()>=0)
				{
					gara.setNro_giorni_da_disputare(
							gara.getNro_giorni_da_disputare()+1);
					nroGiorniDaDisputare.setText(String.valueOf(gara.getNro_giorni_da_disputare()));
				}
			}
		});

		remnroGiorniDaDisputare.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if(listGare.getSelectedIndex()>=0)
				{
					gara.setNro_giorni_da_disputare(
							gara.getNro_giorni_da_disputare()-1);
					nroGiorniDaDisputare.setText(String.valueOf(gara.getNro_giorni_da_disputare()));
				}
			}
		});

		scegliDataInizio.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if(listGare.getSelectedIndex()>=0){
					final DateJDialog d = new DateJDialog(gara.getData_inizio());
					d.setLocationRelativeTo(scegliDataInizio);
					d.setVisible(true);
					d.addWindowListener(new WindowAdapter() {
						@Override
						public void windowClosed(WindowEvent arg0) {
							// TODO Auto-generated method stub
							gara.setData_inizio(d.getCalendar());
							dataInizio.setText(Utility.SDF.format(gara.getData_inizio().getTime()));
						}
					});
				}
			}
		});

		scegliDataFine.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if(listGare.getSelectedIndex()>=0){
					final DateJDialog d = new DateJDialog(gara.getData_fine());
					d.setLocationRelativeTo(scegliDataFine);
					d.setVisible(true);
					d.addWindowListener(new WindowAdapter() {
						@Override
						public void windowClosed(WindowEvent arg0) {
							// TODO Auto-generated method stub
							gara.setData_fine(d.getCalendar());
							dataFine.setText(Utility.SDF.format(gara.getData_fine().getTime()));
						}
					});
				}
			}
		});

		aggiungiPartecipante.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if(listGiocatori.getSelectedIndex()>=0 && listGare.getSelectedIndex()>=0){
					int i = listGiocatori.getSelectedIndex();
					GiocatoreInterface gio = giocatori.get(i);
					if(gara.addGiocatore(gio)){
						vt.add(new Integer(i));
						listGiocatori.setCellRenderer(new SfidanteCellRenderer(vt));
						totSfidanti.setText(String.valueOf(vt.size()));
						try {
							d.getGaraDao().addPartecipanteToGara(gio, gara);
						} catch (SQLException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}else
						JOptionPane.showMessageDialog(getParent(), "Non puoi aggiungere lo sfidante.");
				}
			}
		});

		eliminaPartecipante.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if(listGiocatori.getSelectedIndex()>=0 && listGare.getSelectedIndex()>=0){
					int i = listGiocatori.getSelectedIndex();
					GiocatoreInterface gio = giocatori.get(i);
					if(gara.removeGiocatore(gio)){
						vt.remove(new Integer(i));
						listGiocatori.setCellRenderer(new SfidanteCellRenderer(vt));
						totSfidanti.setText(String.valueOf(vt.size()));
						try {
							d.getGaraDao().removePartecipanteFromGara(gio, gara);
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();

						}
					}else
						JOptionPane.showMessageDialog(getParent(), "Non puoi eliminare lo sfidante.");
				}
			}
		});

		nuovaGara.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				Gara g = new Gara();
				g.setNome(torneo.getNome()+"_gara_"+Utility.SDF_TO_NAME.format(g.getData_inizio().getTime()));
				if(torneo.getCalendario().addGara(g, null)){
					loadList();
					listGare.setSelectedIndex(torneo.getCalendario().getCalendario().size()-1);
					try {
						d.getGaraDao().insert(g);
						d.getGaraDao().addGaraToCalendario(g, torneo);
						d.commit();
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		});

		eliminaGara.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if(listGare.getSelectedIndex()>=0 && torneo.getCalendario().removeGara(gara)){
					try {
						d.getGaraDao().delete(gara);
						d.getGaraDao().removeGaraFromCalendario(gara, torneo);
						d.commit();
						JOptionPane.showMessageDialog(getParent(), "Gara eliminata.");
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					loadList();
					listGare.setSelectedIndex(0);
				}
			}
		});

		salvaGara.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				try {
					GregorianCalendar gf = new GregorianCalendar();
					gf.setTime(Utility.SDF.parse(dataFine.getText()));
					gara.setData_fine(gf);

					GregorianCalendar gi = new GregorianCalendar();
					gi.setTime(Utility.SDF.parse(dataInizio.getText()));
					gara.setData_inizio(gi);

					gara.setNome(nomeGara.getText());
					gara.setNro_giorni_da_disputare(Integer.parseInt(nroGiorniDaDisputare.getText()));

					gara.setSync(tipoGara.getSelectedIndex()==0?false:true);

					if(d.getGaraDao().update(gara))
					{
						JOptionPane.showMessageDialog(getParent(), "Gara modificata e salvata correttamente.");
					}else
					{
						if(d.getGaraDao().insert(gara))
						{
							JOptionPane.showMessageDialog(getParent(), "Gara salvata correttamente.");
						}
						else
							JOptionPane.showMessageDialog(getParent(), "Inserisci correttamenti i dati.");
					}
					d.commit();
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}
		});
	}

	private void initComponents() {

		jSeparator1 = new javax.swing.JSeparator();
		jPanel1 = new javax.swing.JPanel();
		javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
		nroCommissari = new javax.swing.JTextField();
		javax.swing.JLabel jLabel4 = new javax.swing.JLabel();
		tipologiaTorneo = new javax.swing.JTextField();
		javax.swing.JLabel jLabel11 = new javax.swing.JLabel();
		javax.swing.JLabel jLabel9 = new javax.swing.JLabel();
		tipoGiocatori = new javax.swing.JTextField();
		nomeTorneo = new javax.swing.JTextField();
		annoSvolgimentoTorneo = new javax.swing.JTextField();
		javax.swing.JLabel jLabel3 = new javax.swing.JLabel();
		numeroEdizioneTorneo = new javax.swing.JTextField();
		javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
		javax.swing.JLabel jLabel7 = new javax.swing.JLabel();
		totPartecipanti = new javax.swing.JTextField();
		jPanel2 = new javax.swing.JPanel();
		javax.swing.JLabel jLabel5 = new javax.swing.JLabel();
		nomeGara = new javax.swing.JTextField();
		javax.swing.JLabel jLabel6 = new javax.swing.JLabel();
		nroGiorniDaDisputare = new javax.swing.JTextField();
		addnroGiorniDaDisputare = new javax.swing.JButton();
		remnroGiorniDaDisputare = new javax.swing.JButton();
		javax.swing.JLabel jLabel8 = new javax.swing.JLabel();
		dataInizio = new javax.swing.JTextField();
		javax.swing.JLabel jLabel10 = new javax.swing.JLabel();
		dataFine = new javax.swing.JTextField();
		scegliDataInizio = new javax.swing.JButton();
		scegliDataFine = new javax.swing.JButton();
		javax.swing.JLabel jLabel12 = new javax.swing.JLabel();
		tipoGara = new javax.swing.JComboBox();
		jScrollPane2 = new javax.swing.JScrollPane();
		listGiocatori = new javax.swing.JList();
		javax.swing.JLabel jLabel13 = new javax.swing.JLabel();
		javax.swing.JLabel jLabel14 = new javax.swing.JLabel();
		totSfidanti = new javax.swing.JTextField();
		aggiungiPartecipante = new javax.swing.JButton();
		eliminaPartecipante = new javax.swing.JButton();
		jSeparator2 = new javax.swing.JSeparator();
		salvaGara = new javax.swing.JButton();
		jPanel3 = new javax.swing.JPanel();
		jScrollPane3 = new javax.swing.JScrollPane();
		listGare = new javax.swing.JList();
		javax.swing.JLabel jLabel15 = new javax.swing.JLabel();
		javax.swing.JLabel jLabel16 = new javax.swing.JLabel();
		totGare = new javax.swing.JTextField();
		nuovaGara = new javax.swing.JButton();
		eliminaGara = new javax.swing.JButton();

		jLabel1.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel1.setText("Nome torneo");

		nroCommissari.setEditable(false);
		nroCommissari.setColumns(4);
		nroCommissari.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N

		jLabel4.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel4.setText("Anno");

		tipologiaTorneo.setEditable(false);
		tipologiaTorneo.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N

		jLabel11.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel11.setText("Nro partecipanti");

		jLabel9.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel9.setText("Nro commissari");

		tipoGiocatori.setEditable(false);
		tipoGiocatori.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N

		nomeTorneo.setEditable(false);
		nomeTorneo.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N

		annoSvolgimentoTorneo.setEditable(false);
		annoSvolgimentoTorneo.setColumns(4);
		annoSvolgimentoTorneo.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N

		jLabel3.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel3.setText("Numero edizione");

		numeroEdizioneTorneo.setEditable(false);
		numeroEdizioneTorneo.setColumns(4);
		numeroEdizioneTorneo.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N

		jLabel2.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel2.setText("Tipologia");

		jLabel7.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel7.setText("Tipo giocatori");

		totPartecipanti.setEditable(false);
		totPartecipanti.setColumns(4);
		totPartecipanti.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N

		javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout.setHorizontalGroup(
				jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(jPanel1Layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
								.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
										.addComponent(tipologiaTorneo)
										.addComponent(nomeTorneo, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
										.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
												.addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
												.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
												.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
												.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(jPanel1Layout.createSequentialGroup()
																.addComponent(nroCommissari, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(jLabel11)
																.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(totPartecipanti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
																.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(annoSvolgimentoTorneo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
																.addGroup(jPanel1Layout.createSequentialGroup()
																		.addComponent(tipoGiocatori, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
																		.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(numeroEdizioneTorneo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
																		.addContainerGap())
				);
		jPanel1Layout.setVerticalGroup(
				jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(jPanel1Layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(jLabel1)
								.addComponent(nomeTorneo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(jLabel7)
								.addComponent(tipoGiocatori, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(jLabel3)
								.addComponent(numeroEdizioneTorneo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(0, 0, 0)
								.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
										.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel4)
												.addComponent(annoSvolgimentoTorneo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
												.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel2)
														.addComponent(tipologiaTorneo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(jLabel9)
														.addComponent(nroCommissari, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(jLabel11)
														.addComponent(totPartecipanti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
														.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
				);

		jLabel5.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel5.setText("Nome gara");

		nomeGara.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N

		jLabel6.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel6.setText("Nro giorni gara");

		nroGiorniDaDisputare.setEditable(false);
		nroGiorniDaDisputare.setColumns(4);
		nroGiorniDaDisputare.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N

		addnroGiorniDaDisputare.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		addnroGiorniDaDisputare.setText("+");

		remnroGiorniDaDisputare.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		remnroGiorniDaDisputare.setText("-");

		jLabel8.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel8.setText("Data di inizio");

		dataInizio.setEditable(false);
		dataInizio.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N

		jLabel10.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel10.setText("Data di chiusura");

		dataFine.setEditable(false);
		dataFine.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N

		scegliDataInizio.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		scegliDataInizio.setText("Scegli data");

		scegliDataFine.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		scegliDataFine.setText("Scegli data");

		jLabel12.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel12.setText("Tipo gara");

		tipoGara.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		tipoGara.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Asincrona", "Sincrona", "Diretta" }));

		listGiocatori.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		listGiocatori.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
		jScrollPane2.setViewportView(listGiocatori);

		jLabel13.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		jLabel13.setText("Sfidanti");

		jLabel14.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel14.setText("Totale sfidanti");

		totSfidanti.setEditable(false);
		totSfidanti.setColumns(4);
		totSfidanti.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N

		aggiungiPartecipante.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		aggiungiPartecipante.setText("Aggiungi");

		eliminaPartecipante.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		eliminaPartecipante.setText("Elimina");

		salvaGara.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		salvaGara.setText("Salva");

		javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
		jPanel2.setLayout(jPanel2Layout);
		jPanel2Layout.setHorizontalGroup(
				jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(jPanel2Layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
								.addGroup(jPanel2Layout.createSequentialGroup()
										.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
												.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
														.addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
														.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
														.addComponent(dataFine))
														.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
																.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(dataInizio)))
																.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
																		.addComponent(scegliDataInizio)
																		.addComponent(scegliDataFine)))
																		.addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
																		.addGroup(jPanel2Layout.createSequentialGroup()
																				.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
																						.addGroup(jPanel2Layout.createSequentialGroup()
																								.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
																								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																								.addComponent(nroGiorniDaDisputare, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
																								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																								.addComponent(addnroGiorniDaDisputare)
																								.addGap(0, 0, 0)
																								.addComponent(remnroGiorniDaDisputare))
																								.addGroup(jPanel2Layout.createSequentialGroup()
																										.addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
																										.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addComponent(tipoGara, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
																										.addComponent(salvaGara))
																										.addGap(0, 0, Short.MAX_VALUE))
																										.addGroup(jPanel2Layout.createSequentialGroup()
																												.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
																												.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																												.addComponent(nomeGara)))
																												.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																												.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
																														.addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
																														.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE)
																														.addGroup(jPanel2Layout.createSequentialGroup()
																																.addComponent(jLabel14)
																																.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																																.addComponent(totSfidanti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
																																.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
																																.addComponent(aggiungiPartecipante)
																																.addGap(0, 0, 0)
																																.addComponent(eliminaPartecipante)))
																																.addContainerGap())
				);
		jPanel2Layout.setVerticalGroup(
				jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(jPanel2Layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
								.addGroup(jPanel2Layout.createSequentialGroup()
										.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel5)
												.addComponent(nomeGara, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
												.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
												.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(jLabel6)
														.addComponent(nroGiorniDaDisputare, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
														.addComponent(addnroGiorniDaDisputare)
														.addComponent(remnroGiorniDaDisputare))
														.addGap(0, 0, 0)
														.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
																.addComponent(jLabel8)
																.addComponent(dataInizio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
																.addComponent(scegliDataInizio))
																.addGap(0, 0, 0)
																.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
																		.addComponent(jLabel10)
																		.addComponent(dataFine, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addComponent(scegliDataFine))
																		.addGap(0, 0, 0)
																		.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
																				.addComponent(jLabel12)
																				.addComponent(tipoGara, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
																				.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																				.addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																				.addComponent(salvaGara)
																				.addGap(0, 0, Short.MAX_VALUE))
																				.addGroup(jPanel2Layout.createSequentialGroup()
																						.addComponent(jLabel13)
																						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																						.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
																						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																						.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
																								.addComponent(jLabel14)
																								.addComponent(totSfidanti, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
																								.addComponent(aggiungiPartecipante)
																								.addComponent(eliminaPartecipante))))
																								.addContainerGap())
				);

		listGare.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		listGare.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
		jScrollPane3.setViewportView(listGare);

		jLabel15.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		jLabel15.setText("Gare");

		jLabel16.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		jLabel16.setText("Totale gare");

		totGare.setEditable(false);
		totGare.setColumns(4);
		totGare.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N

		nuovaGara.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		nuovaGara.setText("Nuova");

		eliminaGara.setFont(new java.awt.Font("Trebuchet MS", 1, 12)); // NOI18N
		eliminaGara.setText("Elimina");

		javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
		jPanel3.setLayout(jPanel3Layout);
		jPanel3Layout.setHorizontalGroup(
				jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(jPanel3Layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
								.addComponent(jScrollPane3)
								.addGroup(jPanel3Layout.createSequentialGroup()
										.addComponent(jLabel16)
										.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(totGare, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(nuovaGara)
										.addGap(0, 0, 0)
										.addComponent(eliminaGara)
										.addGap(0, 0, Short.MAX_VALUE))
										.addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
										.addContainerGap())
				);
		jPanel3Layout.setVerticalGroup(
				jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(jPanel3Layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(jLabel15)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
								.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(nuovaGara)
										.addComponent(eliminaGara))
										.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel16)
												.addComponent(totGare, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
												.addContainerGap())
				);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
								.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
										.addContainerGap()
										.addComponent(jSeparator1))
										.addGroup(layout.createSequentialGroup()
												.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
												.addGap(0, 0, 0)
												.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
												.addContainerGap())
												.addGroup(layout.createSequentialGroup()
														.addContainerGap()
														.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
														.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
				);
		layout.setVerticalGroup(
				layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addGap(0, 0, 0)
						.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
								.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
								.addGap(17, 17, 17))
				);
	}
	
	private javax.swing.JButton addnroGiorniDaDisputare;
	private javax.swing.JButton aggiungiPartecipante;
	private javax.swing.JTextField annoSvolgimentoTorneo;
	private javax.swing.JTextField dataFine;
	private javax.swing.JTextField dataInizio;
	private javax.swing.JButton eliminaGara;
	private javax.swing.JButton eliminaPartecipante;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JPanel jPanel3;
	private javax.swing.JScrollPane jScrollPane2;
	private javax.swing.JScrollPane jScrollPane3;
	private javax.swing.JSeparator jSeparator1;
	private javax.swing.JSeparator jSeparator2;
	private javax.swing.JList listGare;
	private javax.swing.JList listGiocatori;
	private javax.swing.JTextField nomeGara;
	private javax.swing.JTextField nomeTorneo;
	private javax.swing.JTextField nroCommissari;
	private javax.swing.JTextField nroGiorniDaDisputare;
	private javax.swing.JTextField numeroEdizioneTorneo;
	private javax.swing.JButton nuovaGara;
	private javax.swing.JButton remnroGiorniDaDisputare;
	private javax.swing.JButton salvaGara;
	private javax.swing.JButton scegliDataFine;
	private javax.swing.JButton scegliDataInizio;
	private javax.swing.JComboBox tipoGara;
	private javax.swing.JTextField tipoGiocatori;
	private javax.swing.JTextField tipologiaTorneo;
	private javax.swing.JTextField totGare;
	private javax.swing.JTextField totPartecipanti;
	private javax.swing.JTextField totSfidanti;
}
